var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
      goods_list:[],
      curpage: 1,
      content:"",
      is_show_time: 1,
      
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var content = options.content
    var shop_id = options.shop_id
    
  //判断搜索框是否有值  
    if (options.content ==  "undefined" ){

      var data = {
        shop_id: shop_id,
        id: shop_id,
        keyword: content,
        curpage: that.data.curpage,
        type_wxapp: 'wxapp',
      }

    }else{

      var data = {
        shop_id: shop_id,
        id: shop_id,
        keyword: content,
        curpage: that.data.curpage,
        type_wxapp: 'wxapp',
        search: content
      }

    }
    var url = app.configData.shop.api_url + '/index.php?ctl=Shop&met=goodsList&typ=json'
      wx.request({
        url: url,
        method: 'GET',
        data: data,
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
         
          that.setData({
            goods_list: res.data.data.items,
            shop_id:shop_id,
            is_show_time: 0
          })
        }
      })
  },
  search:function(){
    wx.redirectTo({
      url: '../search_store/search_store?shop_id='+this.data.shop_id
    })
  },
  //跳转至商品详情页
  toProduct: function (e) {
    var goods_id = e.currentTarget.dataset.goods_id
    wx.redirectTo({
      url: '../product_detail/product_detail?goods_id=' + goods_id
    })
  },
  //下拉刷新
  onPullDownRefresh: function () {
    var that = this
    wx.showToast({
      title: '加载中',//提示信息
      icon: 'loading',//成功显示图标
      duration: 2000//时间
    })
    wx.stopPullDownRefresh()
    that.onLoad()
  },
})